/*
 * @Author: lihaogn
 * @Date: 2021-06-12 23:44:45
 * @LastEditTime: 2022-05-28 16:32:19
 * @LastEditors: Please set LastEditors
 * @Description: 路由配置
 * @FilePath: \lix-admin-client-vue2\src\router\index.js
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/common/Login.vue'
import Home from '@/views/layout/index.vue'

import DevelopRoute from './modules/develop/index'
import systemManage from './modules/system-manage/index'

Vue.use(VueRouter)

export const privateRoutes = [DevelopRoute, systemManage]

export const publicRoutes = [
  {
    path: '/redirect',
    component: Home,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/',
    name: 'root',
    redirect: '/welcome',
    component: Home,
    children: [
      {
        path: 'welcome',
        name: 'welcome',
        component: () => import('@/views/common/Welcome.vue'),
        meta: {
          title: '首页',
          iconName: 'el-icon-s-home',
          isMenu: true
        }
      },
      {
        path: '404',
        name: '404',
        component: () => import('@/views/common/404.vue'),
        meta: {
          title: '404'
        }
      }
    ]
  }
]

const createRouter = () =>
  new VueRouter({
    // routes: [...publicRoutes, ...privateRoutes]
    routes: publicRoutes
  })

const router = createRouter()

/**
 * @author: lihaogn
 * @Date: 2021-12-22 09:29:24
 * @description: 重置路由
 * @param {*}
 * @return {*}
 */
export function resetRouter() {
  // 新路由实例matcer，赋值给旧路由实例的matcher，（相当于replaceRouter）
  router.matcher = createRouter().matcher
}

export default router
